import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/news',
    name: 'news',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/NewsView.vue')
  },
  {
    path:'/video',
    name:'video',
    component: () => import('../views/VideoView.vue')
  },
  {
    path:'/seek',
    name:'seek',
    component: () => import('../views/SeekView.vue')
  },
  {
    path:'/plaint',
    name:'plaint',
    component: () => import('../views/PlaintView.vue')
  },
  {
    path:'/carList',
    name:'carList',
    component: () => import('../views/CarListView.vue')
  },
  {
    path:'/topic',
    name:'topic',
    component: () => import('../views/TopicView.vue'),
    meta: {
      keep: true
    }, // 独享路由守卫
    beforeEnter: (to, from, next) => {
      let token = window.localStorage.getItem("token");
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }
  },
  {
    path:'/carAbout',
    name:'carAbout',
    component: () => import('../views/CarAboutView.vue')
  },
  {
    path:'/carPrice',
    name:'carPrice',
    component: () => import('../views/AskPriceView.vue')
  },
  {
    path:'/seekPrice',
    name:'seekPrice',
    component: () => import('../views/SeekPriceView.vue')
  },
  {
    path:'/plaintCon',
    name:'plaintCon',
    component: () => import('../views/PlaintConView.vue')
  },
  {
    path:'/tosu',
    name:'tosu',
    component: () => import('../views/TousuView.vue')
  },{
    path:'/last',
    name:'last',
    component: () => import('../views/PlaintLastView.vue')
  },
  {
    path:'/plaintCon2',
    name:'plaintCon2',
    component: () => import('../views/PlaintTowView.vue')
  },
  {
    path:'/vPlayer',
    name:'vPlayer',
    component: () => import('../views/VIdeoPlayerView.vue')
  },
  {
    path:'/login',
    name:'login',
    component: () => import('../views/loginView.vue')
   
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
